<?php

/**
 * Albireo Kernel
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Kernel
 */

namespace KernelModule;

use Nette\Environment;

/**
 * Sign In Page presenter.
 *
 * @author     pavel, Albireo Solutions
 * @package    Kernel
 */
class SignInPresenter extends BasePresenter {

    public function beforeRender() {
        // Sign In pages can't be cached (recommended by ISO/IEC 27002)
        Environment::getHttpResponse()->setHeader("Cache-Control", "no-cache");
        parent::beforeRender();
    }

    public function renderDefault() {
        if ($this->getUser()->isLoggedIn()) {
            $this->template->loggedIn = true;
            $this->template->canGoToKernel = false;
            try {
                $this->template->canGoToKernel = $this->getUser()->isAllowed("Kernel:Overview", "default");
            } catch(\InvalidStateException $e) {
                // it seems he can't go to kernel for some reason (db unavailibility...)
            }
        } else {
            $this->template->loggedIn = false;
        }
        $this->template->title = _("Sign In");
    }

    /**
     * Sign in form.
     * @return mixed (form)
     */
    protected function createComponentSignInForm() {
        $sign_in_form = new \Celebrio\Forms\SignInComponent(':Kernel:Overview:default');
        $sign_in_form->setFormTitle(_("Sign In"));
        return $sign_in_form;
    }

}